cmake_minimum_required(VERSION 3.16)

project(FileScannerDLL)

# 设置C++标准
set(CMAKE_CXX_STANDARD 17)
set(CMAKE_CXX_STANDARD_REQUIRED ON)

# 设置编译选项
if(WIN32)
    add_definitions(-DFILESCANNER_EXPORTS)
    add_definitions(-DUNICODE -D_UNICODE)
endif()

# 包含目录
include_directories(${CMAKE_CURRENT_SOURCE_DIR}/../Common)

# 源文件
set(SOURCES
    FileScanner.cpp
    DllExports.cpp
)

set(HEADERS
    FileScanner.h
    ../Common/ScannerInterface.h
)

# 创建动态库
add_library(FileScannerDLL SHARED ${SOURCES} ${HEADERS})

# Windows特定设置
if(WIN32)
    # 设置模块定义文件
    set_target_properties(FileScannerDLL PROPERTIES
        LINK_FLAGS "/DEF:${CMAKE_CURRENT_SOURCE_DIR}/FileScannerDLL.def"
    )
    
    # 链接Windows库
    target_link_libraries(FileScannerDLL)
    
    # 设置输出名称
    set_target_properties(FileScannerDLL PROPERTIES
        OUTPUT_NAME "FileScanner"
        PREFIX ""
    )
else()
    # Linux设置
    target_link_libraries(FileScannerDLL pthread)
    
    # 设置输出名称
    set_target_properties(FileScannerDLL PROPERTIES
        OUTPUT_NAME "FileScanner"
        PREFIX "lib"
    )
endif()

# 编译选项
if(MSVC)
    target_compile_options(FileScannerDLL PRIVATE /W4)
else()
    target_compile_options(FileScannerDLL PRIVATE -Wall -Wextra -pthread)
endif()

# 安装规则
install(TARGETS FileScannerDLL
    RUNTIME DESTINATION bin
    LIBRARY DESTINATION lib
    ARCHIVE DESTINATION lib
)

install(FILES ../Common/ScannerInterface.h
    DESTINATION include
)